package cn.xiaoxiang.org.controller;



import cn.xiaoxiang.basic.util.AjaxResult;
import cn.xiaoxiang.basic.util.PageList;
import cn.xiaoxiang.org.domain.Detail;

import cn.xiaoxiang.org.query.DetailQuery;
import cn.xiaoxiang.org.service.DetailService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/det")
public class DetailController {
    @Autowired
    private DetailService detailService;
    //查询全部
    @GetMapping()
    public List<Detail> findAll(){
     return detailService.findAll();
    }
    //单查询
    @GetMapping("/{id}")
    public Detail findById(@PathVariable("id") Long id){
        return detailService.findById(id);
    }
    //删除
    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        detailService.delete(id);
        return AjaxResult.me().success();
    }

    //批量刪除
    @PatchMapping
    public AjaxResult batchdelete(@RequestBody List<Long> ids) {
        detailService.batchdelete(ids);
        return AjaxResult.me().success();
    }
    //修改和增加
    @PutMapping()
    private AjaxResult addOrup(@RequestBody Detail detail){
        if(null!=detail.getId()){
            detailService.update(detail);
        }else {
            detailService.add(detail);
        }
        return AjaxResult.me().success();
    }
    //分页
    @PostMapping()
    public PageList<Detail> queryByPage(@RequestBody DetailQuery query) {
        return detailService.queryByPage(query);
    }

    @GetMapping("/e/{id}")
    public List<Detail> findde( @PathVariable("id") Long id) {
        return detailService.findde(id);

    }
}
